<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: header"></head>

<body class="gray-bg">
<div class="row  border-bottom white-bg dashboard-header">
<!-- <a class="btn btn-success" onclick="sendws()" >	<i class="fa fa-plus"></i> 添加</a> -->
		<div class="col-sm-12">
			<div class="ibox-title">
				<h5>已成功提交([[${#lists.size(acmed)}]])</h5>
			</div>
			<div class="ibox-content" style="border-bottom: solid #00f;" th:with="ac=0">
				<th:block th:each="acm,iterStat: ${acmed}" >
				<span class="label label-success ac"  th:if="${#strings.contains('1001,1278,1279,1282,1284,1285,1286,1287,1288,1289,1290,1294,1298,1299,1300,1301,1306,1681,1310,1311,1312,1314,1316,1317,1264,1266,1268,1333,1272,1275,1276,1324,1325,1334,1335', acm)}" th:text="${acm}"></span>
				<span class="label label-warning" th:unless="${#strings.contains('1001,1278,1279,1282,1284,1285,1286,1287,1288,1289,1290,1294,1298,1299,1300,1301,1306,1681,1310,1311,1312,1314,1316,1317,1264,1266,1268,1333,1272,1275,1276,1324,1325,1334,1335', acm)}" th:text="${acm}"></span>
				
				</th:block>	
				<span id="aced" class="label label-default"	></span>
			</div>
		</div>
		<div class="col-sm-4">
			<div class="ibox-title">
				<h5>签到任务</h5>
			</div>
			<div class="ibox-content">
			<table id="bootstrap-table-sign" data-mobile-responsive="true"></table>			
			</div>
			<div class="ibox-title">
				<h5>acm排名</h5>
			</div>
			<div class="ibox-content">
			<table id="bootstrap-table-acmrank" data-mobile-responsive="true"></table>			
			</div>
		</div>
			<div class="col-sm-4">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>题号与题目(1~18必做)</h5>
					</div>
					<div class="ibox-content">
======第一、二章(8)=============<br>

<a th:if="${#strings.contains(acids,'1001')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1001"><i class="fa fa-link"></i>1001	整数求和</a>
<a th:unless="${#strings.contains(acids,'1001')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1001"><i class="fa fa-link"></i>1001	整数求和</a><br>
<a th:if="${#strings.contains(acids,'1278')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1278"><i class="fa fa-link"></i>1278	概述1（简单输出）</a>
<a th:unless="${#strings.contains(acids,'1278')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1278"><i class="fa fa-link"></i>1278	概述1（简单输出）</a><br>
<a th:if="${#strings.contains(acids,'1279')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1279"><i class="fa fa-link"></i>1279	概述2（输出三角形图案）</a>
<a th:unless="${#strings.contains(acids,'1279')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1279"><i class="fa fa-link"></i>1279	概述2（输出三角形图案）</a><br>
<a th:if="${#strings.contains(acids,'1282')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1282"><i class="fa fa-link"></i>1282	输入输出3(字符)</a>
<a th:unless="${#strings.contains(acids,'1282')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1282"><i class="fa fa-link"></i>1282	输入输出3(字符)</a><br>
<a th:if="${#strings.contains(acids,'1284')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1284"><i class="fa fa-link"></i>1284	输入输出5(数学函数)</a>
<a th:unless="${#strings.contains(acids,'1284')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1284"><i class="fa fa-link"></i>1284	输入输出5(数学函数)</a><br>
<a th:if="${#strings.contains(acids,'1285')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1285"><i class="fa fa-link"></i>1285	顺序结构1(交换变量)</a>
<a th:unless="${#strings.contains(acids,'1285')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1285"><i class="fa fa-link"></i>1285	顺序结构1(交换变量)</a><br>
<a th:if="${#strings.contains(acids,'1286')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1286"><i class="fa fa-link"></i>1286	顺序结构2(3位数反转)</a>
<a th:unless="${#strings.contains(acids,'1286')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1286"><i class="fa fa-link"></i>1286	顺序结构2(3位数反转)</a><br>
<a th:if="${#strings.contains(acids,'1287')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1287"><i class="fa fa-link"></i>1287	顺序结构3(球的体积)</a>
<a th:unless="${#strings.contains(acids,'1287')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1287"><i class="fa fa-link"></i>1287	顺序结构3(球的体积)</a><br>

======第三章(4)=============<br>
<a th:if="${#strings.contains(acids,'1288')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1288"><i class="fa fa-link"></i>1288	选择结构(英文大小写)</a>
<a th:unless="${#strings.contains(acids,'1288')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1288"><i class="fa fa-link"></i>1288	选择结构(英文大小写)</a><br>
<a th:if="${#strings.contains(acids,'1289')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1289"><i class="fa fa-link"></i>1289	选择结构1(是否是闰年)</a>
<a th:unless="${#strings.contains(acids,'1289')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1289"><i class="fa fa-link"></i>1289	选择结构1(是否是闰年)</a><br>
<a th:if="${#strings.contains(acids,'1290')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1290"><i class="fa fa-link"></i>1290	选择结构2(鸡兔同笼)</a>
<a th:unless="${#strings.contains(acids,'1290')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1290"><i class="fa fa-link"></i>1290	选择结构2(鸡兔同笼)</a><br>
<a th:if="${#strings.contains(acids,'1294')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1294"><i class="fa fa-link"></i>1294	选择结构6(分段函数)</a>
<a th:unless="${#strings.contains(acids,'1294')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1294"><i class="fa fa-link"></i>1294	选择结构6(分段函数)</a><br>
======第四章(6)==============<br>
<a th:if="${#strings.contains(acids,'1298')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1298"><i class="fa fa-link"></i>1298	循环结构1(求和)</a>
<a th:unless="${#strings.contains(acids,'1298')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1298"><i class="fa fa-link"></i>1298	循环结构1(求和)</a><br>
<a th:if="${#strings.contains(acids,'1299')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1299"><i class="fa fa-link"></i>1299	循环结构2(整数的和)</a>
<a th:unless="${#strings.contains(acids,'1299')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1299"><i class="fa fa-link"></i>1299	循环结构2(整数的和)</a><br>
<a th:if="${#strings.contains(acids,'1300')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1300"><i class="fa fa-link"></i>1300	循环结构3(连续整数和)</a>
<a th:unless="${#strings.contains(acids,'1300')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1300"><i class="fa fa-link"></i>1300	循环结构3(连续整数和)</a><br>
<a th:if="${#strings.contains(acids,'1301')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1301"><i class="fa fa-link"></i>1301	循环结构4(阶乘之和)</a>
<a th:unless="${#strings.contains(acids,'1301')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1301"><i class="fa fa-link"></i>1301	循环结构4(阶乘之和)</a><br>
<a th:if="${#strings.contains(acids,'1306')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1306"><i class="fa fa-link"></i>1306	循环结构9(求素数)</a>
<a th:unless="${#strings.contains(acids,'1306')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1306"><i class="fa fa-link"></i>1306	循环结构9(求素数)</a><br>
<a th:if="${#strings.contains(acids,'1681')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1681"><i class="fa fa-link"></i>1681 循环结构(3,7的倍数之和)</a>
<a th:unless="${#strings.contains(acids,'1681')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1681"><i class="fa fa-link"></i>1681 循环结构(3,7的倍数之和)</a><br>
		</div>
        </div>

    </div>
			<div class="col-sm-4">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>题号与题目(19~35必做)</h5>
					</div>
					<div class="ibox-content">
======第五章(6)==============<br>
<a th:if="${#strings.contains(acids,'1310')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1310"><i class="fa fa-link"></i>1310	数组1(菲波那契数列)</a>
<a th:unless="${#strings.contains(acids,'1310')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1310"><i class="fa fa-link"></i>1310	数组1(菲波那契数列)</a><br>
<a th:if="${#strings.contains(acids,'1311')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1311"><i class="fa fa-link"></i>1311 数组2(统计各类字符的个数)</a>
<a th:unless="${#strings.contains(acids,'1311')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1311"><i class="fa fa-link"></i>1311 数组2(统计各类字符的个数)</a><br>
<a th:if="${#strings.contains(acids,'1312')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1312"><i class="fa fa-link"></i>1312 数组3(排序)</a>
<a th:unless="${#strings.contains(acids,'1312')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1312"><i class="fa fa-link"></i>1312 数组3(排序)</a><br>
<a th:if="${#strings.contains(acids,'1314')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1314"><i class="fa fa-link"></i>1314 数组5(矩阵对角线元素之和)</a>
<a th:unless="${#strings.contains(acids,'1314')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1314"><i class="fa fa-link"></i>1314 数组5(矩阵对角线元素之和)</a><br>
<a th:if="${#strings.contains(acids,'1316')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1316"><i class="fa fa-link"></i>1316 数组7(统计英文字母个数)</a>
<a th:unless="${#strings.contains(acids,'1316')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1316"><i class="fa fa-link"></i>1316 数组7(统计英文字母个数)</a><br>
<a th:if="${#strings.contains(acids,'1317')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1317"><i class="fa fa-link"></i>1317 数组8(统计各分数段的人数)</a>
<a th:unless="${#strings.contains(acids,'1317')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1317"><i class="fa fa-link"></i>1317 数组8(统计各分数段的人数)</a><br>

======第六章(5)=============<br>
<a th:if="${#strings.contains(acids,'1264')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1264"><i class="fa fa-link"></i>1264 函数1（最大公约数）</a>
<a th:unless="${#strings.contains(acids,'1264')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1264"><i class="fa fa-link"></i>1264 函数1（最大公约数）</a><br>
<a th:if="${#strings.contains(acids,'1266')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1266"><i class="fa fa-link"></i>1266 函数3（有序数组插入）</a>
<a th:unless="${#strings.contains(acids,'1266')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1266"><i class="fa fa-link"></i>1266 函数3（有序数组插入）</a><br>
<a th:if="${#strings.contains(acids,'1268')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1268"><i class="fa fa-link"></i>1268 函数5（数组倒序）</a>
<a th:unless="${#strings.contains(acids,'1268')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1268"><i class="fa fa-link"></i>1268 函数5（数组倒序）</a><br>
<a th:if="${#strings.contains(acids,'1333')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1333"><i class="fa fa-link"></i>1333 C语言实验四(函数)：题目2、递归计算n!</a>
<a th:unless="${#strings.contains(acids,'1333')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1333"><i class="fa fa-link"></i>1333 C语言实验四(函数)：题目2、递归计算n!</a><br>
<a th:if="${#strings.contains(acids,'1272')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1272"><i class="fa fa-link"></i>1272 递归函数4（连续偶数和）</a>
<a th:unless="${#strings.contains(acids,'1272')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1272"><i class="fa fa-link"></i>1272 递归函数4（连续偶数和）</a><br>
======第七章(2)=============<br>
<a th:if="${#strings.contains(acids,'1275')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1275"><i class="fa fa-link"></i>1275 结构体2(计算年龄)</a>
<a th:unless="${#strings.contains(acids,'1275')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1275"><i class="fa fa-link"></i>1275 结构体2(计算年龄)</a><br>
<a th:if="${#strings.contains(acids,'1276')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1276"><i class="fa fa-link"></i>1276 结构体3(按学生总分排序)</a>
<a th:unless="${#strings.contains(acids,'1276')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1276"><i class="fa fa-link"></i>1276 结构体3(按学生总分排序)</a><br>
======第八章(4)==============<br>
<a th:if="${#strings.contains(acids,'1324')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1324"><i class="fa fa-link"></i>1324 指针4(求字符串的子串)</a>
<a th:unless="${#strings.contains(acids,'1324')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1324"><i class="fa fa-link"></i>1324 指针4(求字符串的子串)</a><br>
<a th:if="${#strings.contains(acids,'1325')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1325"><i class="fa fa-link"></i>1325 指针5(连接字符串)</a>
<a th:unless="${#strings.contains(acids,'1325')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1325"><i class="fa fa-link"></i>1325 指针5(连接字符串)</a><br>
<a th:if="${#strings.contains(acids,'1334')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1334"><i class="fa fa-link"></i>1334 C语言实验五(指针)：题目1、统计成绩</a>
<a th:unless="${#strings.contains(acids,'1334')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1334"><i class="fa fa-link"></i>1334 C语言实验五(指针)：题目1、统计成绩</a><br>
<a th:if="${#strings.contains(acids,'1335')}" class="btn btn-success btn-xs" href="/acm/front/detail?problemId=1335"><i class="fa fa-link"></i>1335 C语言实验五(指针)：题目2、排序与查找</a>
<a th:unless="${#strings.contains(acids,'1335')}" class="btn btn-default btn-xs" href="/acm/front/detail?problemId=1335"><i class="fa fa-link"></i>1335 C语言实验五(指针)：题目2、排序与查找</a>



		</div>
        </div>

    </div>
		
</div>
<!--
<div class="wrapper wrapper-content">
    <div class="row">
			<div class="col-sm-4">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>技术选型：</h5>
					</div>
					<div class="ibox-content">
						<ol>
							<li>核心框架：NutzBoot。</li>
							<li>安全框架：Apache Shiro。</li>
							<li>模板引擎：Thymeleaf。</li>
							<li>缓存：Caffeine。</li>
							<li>定时任务:Quartz。</li>
							<li>数据库：MySQL。</li>
							<li>数据库连接池：Druid。</li>
							<li>工具类：Fastjson。</li>
							<li>Office 工具：POI</li>
							<li>前端组件：jQuery、Bootstrap、Bootstrap-table、layer、zTree、jquery-validation</li>
							<li>更多……</li>
						</ol>
					</div>
				</div>
			</div>
			<div class="col-sm-8">
            <div class="ibox float-e-margins">
            	<div class="ibox-title">
                    <h5>更新日志</h5>
                </div>
                <div class="ibox-content">
					<table id="bootstrap-table" data-mobile-responsive="true"></table>
					</div>
            </div>
        </div>

    </div>
</div>-->


    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
var now0=stdTime([[${now0}]]);
//首先,需要创建一个WebSocket连接
var ws, lockReconnect = false;  //避免ws重复连接
var WS_URL =   window.location.host+"/websocket";
$(function() {
	var options2 = {
			id:"bootstrap-table-sign",
            url: ctx + "signin/sned/list2",
            method: 'post',                                     // 请求方式（*）
            cache: false,                                       // 是否使用缓存
            striped: true,                                  // 是否显示行间隔色
            sortable: true,                                     // 是否启用排序
            sortStable: true,                                   // 设置为 true 将获得稳定的排序
            sortName: "desc",                                // 排序列名称
            sortOrder: "snstarttime",                              // 排序方式  asc 或者 desc
            pagination: true,   // 是否显示分页（*）
            pageNumber: 1,                                      // 初始化加载第一页，默认第一页
            pageSize: 50,                                       // 每页的记录行数（*） 
            pageList: [10, 25, 50],                             // 可供选择的每页的行数（*）
            escape: false,                                    // 转义HTML字符串
            iconSize: 'outline',                                // 图标大小：undefined默认的按钮尺寸 xs超小按钮sm小按钮lg大按钮
            sidePagination: "server",                           // 启用服务端分页
            search: false,           // 是否显示搜索框功能
            showSearch: false,   // 是否显示检索信息
            showRefresh: false, // 是否显示刷新按钮
			showColumns: false, // 是否显示隐藏某列下拉框
			showToggle: false,   // 是否显示详细视图和列表视图的切换按钮
			showExport: false,   // 是否支持导出文件
            //queryParams: $.table.queryParams,                     // 传递参数（*）
	columns : [ {
				formatter : function(value, row, index) {
					return row.snpub.title;//
					/* var actions = [];
					actions.push(row.snpub.title+'<a class="btn btn-success" href="#" ><i class="fa fa-edit"></i>进行中...</a>');
					return actions.join('');; */
				}
			},
			{
	            align: 'center',
	            formatter: function(value, row, index) {
	            	var actions = [];
	            	var snstarttime=stdTime(row.snpub.snstarttime);
	            	var snendtime=row.snpub.snendtime.replace(/-/g,"/");
	            	var snenddelay90=0;
	            	if(row.snpub.hasendtime) snendtime=Date.parse(snendtime);
	            	if(row.status==0)
	            		actions.push('<a class="btn btn-success btn-xs " href="#" ><i class="fa fa-check"></i>已签到</a>');
	            	else if(row.status>0)
	            		actions.push('<a class="btn btn-success btn-xs " href="#" ><i class="fa fa-edit"></i>已签迟到'+row.status+'分钟</a>');
	            	else{ 
	            		if(snstarttime>now0)
		            		actions.push('<a class="btn btn-warning btn-xs " href="#" ><i class="fa fa-edit"></i>签到未开始</a>');
		            	else if((!row.snpub.hasendtime || snendtime>now0)) //手工结束或未到结束时
		            		actions.push('<a class="btn btn-info btn-xs " href="#" onclick="$.operate.get(\'' +ctx + 'signin/sned/edit2/'+row.snid + '\')"><i class="fa fa-edit"></i>签到</a>');
                        else if((now0-snendtime)/60000<=90) //超时迟到了
                        	actions.push('<a class="btn btn-primary btn-xs " href="#" onclick="$.operate.get(\'' +ctx + 'signin/sned/edit2/'+row.snid + '\')"><i class="fa fa-edit"></i>签迟到</a>');
                        else actions.push('<a class="btn btn-danger btn-xs " href="#" ><i class="fa fa-close"></i>缺勤</a>');
	            	}
					return actions.join('');
	            }
	        }
		 ]
	};
	$.table.init(options2);

	var options = {
		url : ctx + "sys/updlog/list",
		//modalName: "更新日志",
		striped : true,
		search : false,
		showSearch : false,
		showRefresh : false,
		showColumns : false,
		showToggle : false,
		showExport : false,
		sortOrder : "desc",
		sortName : "updateTime",
		columns : [ {
			field : 'updateTime',
			//title : '更新时间',
			formatter : function(value, row, index) {
				return value.substring(0, 10);
			},
			width : 150
		}, {
			field : 'content'
		//,title : '更新内容'
		} ]
	};
	$.table.init(options);

	var options5 = {
			id:"bootstrap-table-acmrank",
            url: ctx + "acm/front/listrank2",
            modalName: "AC排名",
            striped:true,
			search: false,
			showSearch:false,
			showRefresh:false,
			showColumns:false,
			showToggle:false,
			showExport:false,
			sortOrder:"desc",
			sortName:"solved",
			pageSize: 50,
			pageNumber:1,
            columns: [
  				{
					field : 'id', 
					title : '用户名',
					formatter: function(value, row, index) {
						if($.table.getPageNum('bootstrap-table')==1){
    						if(index==0) return value+"<img style='width:20px;margin-left:5px;' src='"+ctx+"assets/img/gold.png' />";
    						else if(index==1) return value+"<img style='width:20px;margin-left:5px;' src='"+ctx+"assets/img/silver.png' />";
    						else if(index==2) return value+"<img style='width:20px;margin-left:5px;' src='"+ctx+"assets/img/copper.png' />";
    						else return value;
						}else return value;
					}
				},
			{
				field : 'solved', 
				title : 'AC题数'
			},
			{
				field : 'submit', 
				title : '提交次数'
			}]
        };
        $.table.init(options5);
	
    $("#aced").html("已完成必做题数："+$(".ac").length);
if(typeof(WebSocket) == "undefined") {
	$.modal.msgError("您的浏览器不支持WebSocket");
}else{
	var wsUrl;
	 // 如果页面是https,那么必须走wss协议, 否则走ws协议
	if (location.protocol == 'http:') {
		wsUrl="ws://"+WS_URL;
	} else {
		wsUrl="wss://"+WS_URL;
	}	
	//createWebSocket(wsUrl);   //连接ws

}

});
function initEventHandle() {
	// 连接成功后,会触发onopen回调
	ws.onopen = function(event) {    // 加入home房间
	    ws.send(JSON.stringify({room:'home',"action":"join"}));
	};
	// 收到服务器发来的信息时触发的回调
	ws.onmessage = function(event) {
	    console.log("websocket onmessage", event.data);
	    //heartCheck.reset().start();//心跳检测重置
	    var re = JSON.parse(event.data);
	    if (re.action == "notify") {// 弹个浏览器通知
	        $.modal.confirm(re.body, function(){
	        	
	        });
	    } else if (re.action == "msg") {
	        // 插入到聊天记录中
	    	$.modal.msgSuccess(re.msg);
	    }else if (re.action == "layer") {
	        // 插入到聊天记录中
	    	$.modal.msgSuccess(re.msg);
	    }else if (re.action == "offline") {
	        ws.close();
	        top.location.href="/";
	    }
	};
	//连接发生错误的回调方法
	ws.onerror = function () {		
		$.modal.msgError("WebSocket连接发生错误");
	};
	//连接关闭的回调方法
	ws.onclose = function (e) {
		console.log('websocket 断开: ' + e.code + ' ' + e.reason + ' ' + e.wasClean)
	}
	setInterval("ws_ping()", 60000);
}
/* function createWebSocket(url) {
    try{
        if('WebSocket' in window){
            ws = new WebSocket(url);
        }
        initEventHandle();
    }catch(e){
        reconnect(url);
        console.log(e);
    }     
} */

// 定时发个空消息,避免服务器断开连接
function ws_ping() {
	if (ws) {
		//ws.send("{}"); 
	}
}
function sendws(){
	$.operate.post2(ctx+"sys/msgUser/sendmsg",{"ids":"admin", "msg" : "湖南人文科技学院"});
}
//监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
window.onbeforeunload = function() {
   // ws.close();
}
function reconnect(url) {
    if(lockReconnect) return;
    lockReconnect = true;
    setTimeout(function () {     //没连接上会一直重连，设置延迟避免请求过多
        createWebSocket(url);
        lockReconnect = false;
    }, 2000);
}

//心跳检测
var heartCheck = {
    timeout: 30000,        //1分钟发一次心跳
    timeoutObj: null,
    serverTimeoutObj: null,
    reset: function(){
        clearTimeout(this.timeoutObj);
        clearTimeout(this.serverTimeoutObj);
        return this;
    },
    start: function(){
        var self = this;
        this.timeoutObj = setTimeout(function(){
            //这里发送一个心跳，后端收到后，返回一个心跳消息，
            //onmessage拿到返回的心跳就说明连接正常
            //ws.send("ping");
            ws.send("{}");
            console.log("ping!")
            self.serverTimeoutObj = setTimeout(function(){//如果超过一定时间还没重置，说明后端主动断开了
                ws.close();     //如果onclose会执行reconnect，我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
            }, self.timeout)
        }, this.timeout)
    }
}
</script>
</body>
</html>
